/***************************************************************************
 *   Copyright (C) 2007 by Gaetano Mendola  *
 *   mendola@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <stdexcept>
#include <iostream>
#include <assert.h>

#include "flurry.h"

#include "../events/event.h"
#include "../events/eventdispatcher.h"

#include "../buffs/flurry.h"

#include "../player.h"

namespace Talents {

Flurry::Flurry(unsigned char aRank)
:Talent(),
 EventSink(),
 theIncreaseAttackSpeed(attackSpeed(aRank))
{

}

Flurry::~Flurry()
{
    Events::EventDispatcher::instance().unsubscribe(this);
}

void Flurry::learned(Player *aPlayer)
{
    Events::EventDispatcher::instance().subscribe(Events::Event::CRITMELEE, this);

    assert(!thePlayer);
    thePlayer = aPlayer;
}

void Flurry::notify(const Events::Event* anEvent)
{
    Events::Event::TYPE myType = anEvent->type();

    if ( myType == Events::Event::CRITMELEE ) {
        assert(thePlayer);

        Buffs::Flurry *myBuff = new Buffs::Flurry(theIncreaseAttackSpeed);
        thePlayer->addBuff(myBuff);
    } 
}

unsigned char Flurry::attackSpeed(unsigned char aRank) 
{
    switch (aRank) 
    {
        case 1: return 10; 
        case 2: return 15;
        case 3: return 20; 
        case 4: return 25; 
        case 5: return 30; 
        default: throw std::runtime_error("Flurry rank it should be 1,2,3,4,5");
    }

}


}


